package com.app.service.impl;

import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.app.annotion.RedisLockAnnotation;
import com.app.common.Result;
import com.app.common.SystemConstant;
import com.app.exception.BaseException;
import com.app.mapper.*;
import com.app.model.*;
import com.app.service.*;
import com.app.utils.*;
import com.app.vo.UserVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
import com.github.binarywang.wxpay.constant.WxPayConstants;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.yulichang.query.MPJQueryWrapper;
import com.google.j2objc.annotations.ObjectiveCName;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.imageio.stream.ImageInputStream;
import javax.security.auth.login.LoginException;
import java.io.File;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

import static cn.hutool.crypto.digest.DigestUtil.md5Hex;
import static com.app.common.SystemConstant.DEFAULT_PDF_SERVICE_URL;
import static com.app.service.impl.CustomerServiceServiceImpl.convertIntListToString;

@Slf4j
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserModel> implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private InviteConfigService inviteConfigService;
    @Autowired
    private WxPayService wxService;
    @Autowired
    private TransferRecordsMapper transferRecordsMapper;
    @Autowired
    private InviteRecordService inviteRecordService;
    @Autowired
    private PayMapper payMapper;
    @Autowired
    private IntegralRecordService integralRecordService;
    @Autowired
    private VoucherRecordMapper voucherRecordMapper;
    @Autowired
    private DistributionRecordsMapper distributionRecordsMapper;
    @Autowired
    private MessageBoxMapper messageBoxMapper;
    @Autowired
    private InviteConfigMapper inviteConfigMapper;
    @Value("${wx.pay.mchId}")
    private String mchId;
    @Value("${wx.pay.payNotify}")
    private String payNotify;
    @Autowired
    private CityMapper cityMapper;
    @Autowired
    private AreaMapper areaMapper;
    @Autowired
    private InvationCodeMapper invationCodeMapper;
    @Autowired
    private InviteRecordMapper inviteRecordMapper;
    @Autowired
    private UserService userService;
    @Autowired
    private IntegralRecordMapper integralRecordMapper;
    @Autowired
    private AliyunOSSUtils aliyunOSSUtils;
    @Autowired
    private CustomerServiceService customerServiceService;
    @Autowired
    private CustomerServiceMapper customerServiceMapper;
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private IntegralOrderMapper inviteOrderMapper;
    @Autowired
    private TransferRecordsMapper transferRecordsDao;
    @Resource
    private SMSUtils smsUtils;

    @Override
    public UserVo getList(Integer page, Integer limit, String keyword, AdminUserModel user, String areaId, Integer identity,String beginTime,String endTime,Integer ifVip) {
        MPJQueryWrapper<UserModel> queryWrapper = new MPJQueryWrapper<>();
        queryWrapper.selectAll(UserModel.class);
        queryWrapper.select("ta.area", "tc.city", "tp.province");
        queryWrapper.leftJoin("tbc_areas ta on t.area_id = ta.area_id");
        queryWrapper.leftJoin("tbc_cities tc on ta.city_id = tc.city_id");
        queryWrapper.leftJoin("tbc_provinces tp on tc.province_id = tp.province_id");

        if (StrUtil.isNotBlank(areaId)) {
            queryWrapper.eq("t.area_id", areaId);
        }
        if (StrUtil.isNotBlank(keyword)) {
            queryWrapper.like("t.phone",keyword);
        }

        if (StrUtil.isNotBlank(beginTime) && StrUtil.isNotBlank(endTime)) {
            // 注意：这里的时间格式需要与数据库中的 TIMESTAMP 格式匹配
            queryWrapper.between("t.create_time", beginTime, endTime);
        }

        queryWrapper.eq(ifVip != null, "t.vip", ifVip);

        if (null != identity){
            if (1 == identity){//商家
                queryWrapper.eq("t.status", 2);
            }else if (2 == identity){//会员
                queryWrapper.eq( "t.vip", 1);

                // 如果 beginTime 和 endTime 不为空，则添加时间范围查询
                if (StrUtil.isNotBlank(beginTime) && StrUtil.isNotBlank(endTime)) {
                    // 注意：这里的时间格式需要与数据库中的 TIMESTAMP 格式匹配
                    queryWrapper.between("t.create_time", beginTime, endTime);
                }
            }else if (3 == identity || 4 == identity){//3市代理 4区代理
                queryWrapper.eq("role_id", identity);
            }else if (5 == identity){//普通用户
                queryWrapper.eq( "t.vip", 2);
            }
        }

        Page<UserModel> pages = new Page<>();
        pages.setCurrent(page);
        pages.setSize(limit);
        Page<UserModel> userModelPage = userMapper.selectPage(pages, queryWrapper);
        List<UserModel> userList = userModelPage.getRecords();
        for (UserModel userModel : userList) {
            if (userModel.getProvince() != null) {
                userModel.setAreaText(userModel.getProvince() + "/" + userModel.getCity() + "/" + userModel.getArea());
            }
            userModel.setOpenId(null);
            //统计用户月消费-券(团购+商品兑换+转账)
            Double orderCoupons = orderMapper.getMonthlyConsumption(userModel.getId());
            Double inviteOrderCoupons = inviteOrderMapper.getMonthlyConsumption(userModel.getId());
            Double transferCoupons = transferRecordsDao.getMonthlyConsumption(userModel.getId());
            Double allCoupons = orderCoupons + inviteOrderCoupons + transferCoupons;
            //统计用户月消费-积分(商品兑换)
            Double inviteOrderPoints = inviteOrderMapper.getMonthlyPointsConsumption(userModel.getId());
            userModel.setAllCoupons(allCoupons);
            userModel.setInviteOrderPoints(inviteOrderPoints);
        }
        UserVo vo = new UserVo();
        vo.setList(userList);
        vo.setCount((int) userModelPage.getTotal());
        return vo;
    }


    @Override
    public com.alibaba.fastjson.JSONObject getUserAllCount(String keyword, AdminUserModel user, String areaId, Integer identity, String beginTime, String endTime) {
        com.alibaba.fastjson.JSONObject object = new com.alibaba.fastjson.JSONObject();
        // 定义时间格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        MPJQueryWrapper<UserModel> queryWrapper = new MPJQueryWrapper<>();
        queryWrapper.selectAll(UserModel.class);
        queryWrapper.select("ta.area", "tc.city", "tp.province");
        queryWrapper.leftJoin("tbc_areas ta on t.area_id = ta.area_id");
        queryWrapper.leftJoin("tbc_cities tc on ta.city_id = tc.city_id");
        queryWrapper.leftJoin("tbc_provinces tp on tc.province_id = tp.province_id");
        if (StrUtil.isNotBlank(areaId)) {
            queryWrapper.eq("t.area_id", areaId);
        }
        if (StrUtil.isNotBlank(keyword)) {
            queryWrapper.last("AND (t.name LIKE CONCAT('%', " + keyword + ", '%') OR t.phone LIKE CONCAT('%', " + keyword + ", '%')) order by t.id desc");
        }
        queryWrapper.eq( "t.vip", 2);

        List<UserModel> allUserList = userMapper.selectList(queryWrapper);


        // 如果 beginTime 和 endTime 不为空，则添加时间范围查询
        if (StrUtil.isNotBlank(beginTime) && StrUtil.isNotBlank(endTime)) {
            // 注意：这里的时间格式需要与数据库中的 TIMESTAMP 格式匹配
            queryWrapper.between("t.create_time", beginTime, endTime);
        }else {
            // 当前年份的第一天 00:00:00
            LocalDate currentYearStart = LocalDate.now().withMonth(1).withDayOfMonth(1);
            LocalDateTime beginTimeDefault = currentYearStart.atStartOfDay();
            // 当前时间
            LocalDateTime endTimeDefault = LocalDateTime.now();
            // 格式化为字符串
            beginTime = beginTimeDefault.format(formatter);
            endTime = endTimeDefault.format(formatter);
            queryWrapper.between("t.create_time", beginTime, endTime);
        }
        List<UserModel> newUserList = userMapper.selectList(queryWrapper);

        object.put("allCount", allUserList.size());
        object.put("newCount", newUserList.size());
        return object;
    }


    @Override
    public void updateStatus(Integer id, Integer status) {
        UserModel model = new UserModel();
        model.setId(id);
        model.setStatus(status);
        userMapper.updateById(model);
    }


    @Override
    public UserModel getOpenid(String code) throws LoginException {
        //获取openid
        String openid = WechatUtil.getOpenid(code);
        if (openid == null) {
            throw new LoginException("openid为空");
        }
        //根据openid查询用户信息
        UserModel user = userMapper.getByOpenid(openid);
        if (user == null) {
            //当前是新用户,返回用户信息
            user = new UserModel();
            user.setFaceUrl(SystemConstant.DEFAULT_FACE_URL);//默认头像
            user.setName("用户" + RandomUtil.randomString(8));//默认昵称
            user.setPhone("");
            user.setStatus(1);
            user.setOpenId(openid);
            user.setCreateTime(CommonHelp.getNowTimestamp());
        }
        return user;
    }

    @Override
    public String getPhone(String code) throws Exception {
        String mobile = WechatUtil.getMobile(code);
        return mobile;
    }

    @Override
    public UserModel getUserByOpenid(String openId) {
        QueryWrapper<UserModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("open_id", openId);
        queryWrapper.last("limit 1");
        UserModel userModel = userMapper.selectOne(queryWrapper);
        return userModel;
    }

    @Autowired
    private IDividedIntoRecordService dividedIntoRecordService;

    @Autowired
    private AdminUserService adminUserService;

    @Autowired
    private BusinessService businessService;

    @Override
    public UserModel isTransferAccounts(UserModel beneficiary, Double transferAmount, UserModel user) {
//        &&用户不为商家
        if(beneficiary.getStatus()==1)
        {
            //商家给会员转账不抽水，也没有积分
            BusinessModel businessModel=this.businessService.getByUserPhone(user.getPhone());
            //商家不为空&&用户为会员
            if(businessModel!=null&&user.getVip()==1&&user.getStatus()==2)
            {
                merchanttomemberVoucherTransferLogic(beneficiary,transferAmount,user);
                user.setMobilePhoneNumberOppositeTransferAccount(beneficiary.getPhone());
                return user;
            }
        }

        Double originalTransferFee=transferAmount;
        List<InviteConfigModel> inviteConfigModelList = inviteConfigService.list();
        //手续费比例
        Double transactionFeeRatio = inviteConfigModelList.get(0).getTransactionFeeRatio();
        //手续费
        double handlingFees = transferAmount * transactionFeeRatio;
        //谁收券抽谁的
        BigDecimal newTransferAmount = BigDecimal.valueOf(transferAmount).subtract(BigDecimal.valueOf(handlingFees));

        beneficiary.setVoucher(beneficiary.getVoucher() + transferAmount - handlingFees);
        userMapper.updateById(beneficiary);
        //生成转账记录
        TransferRecordsModel transferRecordsModel = new TransferRecordsModel();
        transferRecordsModel.setUserId(user.getId());
        //添加收款人
        transferRecordsModel.setCollectionId(beneficiary.getId());
        transferRecordsModel.setAmount(newTransferAmount.toString());
        transferRecordsModel.setHandlingFees(handlingFees);
        transferRecordsModel.setProportion(transactionFeeRatio);
        transferRecordsModel.setCreateTime(CommonHelp.getNowTimestamp());
        transferRecordsMapper.insert(transferRecordsModel);
        //获取返佣比例
        Double brokerage = inviteConfigModelList.get(0).getBrokerage();
        Double brokerageTwo = inviteConfigModelList.get(0).getBrokerageTwo();
        //分佣积分
        double fist = transferAmount * inviteConfigModelList.get(0).getConversion() * brokerage;
        double second = transferAmount * inviteConfigModelList.get(0).getConversion() * brokerageTwo;
        //一级分佣

        user.setIntegral(user.getIntegral() + fist);
        user.setVoucher(user.getVoucher() - transferAmount);
        userMapper.updateById(user);
        //新增积分记录
        IntegralRecordModel integralRecordModel = new IntegralRecordModel();
        integralRecordModel.setName("转账返还积分");
        integralRecordModel.setTypeName("返还积分");
        integralRecordModel.setContent("向" + beneficiary.getPhone() + "转账");
        String amountIntegral = String.format("+%.2f分", fist);
        integralRecordModel.setIntegral(amountIntegral);
        integralRecordModel.setUserId(user.getId());
        integralRecordModel.setCreateTime(CommonHelp.getNowTimestamp());
        integralRecordModel.setVoucherType(1);
        integralRecordModel.setVoucherAmount(fist);
        integralRecordMapper.insert(integralRecordModel);
        //二级分佣
        QueryWrapper<InviteRecordModel> inviteRecordQW = new QueryWrapper<>();
        inviteRecordQW.eq("quilt_invite_id", user.getId());
        inviteRecordQW.orderByDesc("create_time");
        inviteRecordQW.last("limit 1");
        InviteRecordModel inviteRecordModel = inviteRecordMapper.selectOne(inviteRecordQW);
        if (inviteRecordModel != null && inviteRecordModel.getInviteId() != null) {
            UserModel inviteUser = userService.getById(inviteRecordModel.getInviteId());//此用户的邀请人对象
            if (inviteUser != null) {
                inviteUser.setIntegral(inviteUser.getIntegral() + second);
                userService.updateById(inviteUser);
                //新增积分记录
                IntegralRecordModel integralRecordModel1 = new IntegralRecordModel();
                integralRecordModel1.setName("粉丝贡献积分(转账)");
                integralRecordModel1.setTypeName("贡献积分(转账)");
                integralRecordModel1.setContent(user.getName() + "转账");
                String amountIntegral1 = String.format("+%.2f分", second);
                integralRecordModel1.setIntegral(amountIntegral1);
                integralRecordModel1.setUserId(inviteUser.getId());
                integralRecordModel1.setVoucherType(1);
                integralRecordModel1.setVoucherAmount(second);
                integralRecordModel1.setCreateTime(CommonHelp.getNowTimestamp());
                integralRecordMapper.insert(integralRecordModel1);
            }
        }
        else {
            //给平台用户发放积分
            this.adminUserService.accumulatePointsForCurrentPlatformUser(user.getId(),"好友转账上级分佣积分",BigDecimal.valueOf(second));
        }
        //生成转账人益联券使用记录
        VoucherRecordModel quiltUserVoucherRecord = new VoucherRecordModel();
        quiltUserVoucherRecord.setName("好友转账");
        quiltUserVoucherRecord.setTypeName("好友转账");
        quiltUserVoucherRecord.setContent("向" + beneficiary.getPhone() + "转账");
        String amountVoucher = "-" + transferAmount + "券";
        quiltUserVoucherRecord.setVoucher(amountVoucher);
        quiltUserVoucherRecord.setUserId(user.getId());
        quiltUserVoucherRecord.setVoucherType(0);
        quiltUserVoucherRecord.setFees(BigDecimal.valueOf(handlingFees));
        quiltUserVoucherRecord.setVoucherAmount(-originalTransferFee);
        quiltUserVoucherRecord.setCreateTime(CommonHelp.getNowTimestamp());
        voucherRecordMapper.insert(quiltUserVoucherRecord);
        //消息盒子记录数据两条
        MessageBoxModel messageBoxModel0 = new MessageBoxModel();
        //转账人
        messageBoxModel0.setUserId(user.getId());
        messageBoxModel0.setQuiltUserId(user.getId());
        messageBoxModel0.setTypeName("转账通知");
        //需要显示原代金券
        messageBoxModel0.setVoucher(transferAmount.doubleValue());
        messageBoxModel0.setNotes("向" + beneficiary.getPhone() + "转账");
        messageBoxModel0.setCreateTime(CommonHelp.getNowTimestamp());
        messageBoxModel0.setOrderSn(IdUtil.getSnowflakeNextIdStr());
        messageBoxMapper.insert(messageBoxModel0);
        //生成被转账人益联券使用记录
        VoucherRecordModel userVoucherRecord = new VoucherRecordModel();
        userVoucherRecord.setName("好友转账");
        userVoucherRecord.setTypeName("收到好友转账");
        userVoucherRecord.setContent("收到" + user.getPhone() + "转账");
        String amountVoucherUser = "+" + (newTransferAmount.doubleValue()) + "券";
        userVoucherRecord.setVoucher(amountVoucherUser);
        userVoucherRecord.setUserId(beneficiary.getId());
        userVoucherRecord.setCreateTime(CommonHelp.getNowTimestamp());
        userVoucherRecord.setVoucherType(1);
        userVoucherRecord.setVoucherAmount(newTransferAmount.doubleValue());
        voucherRecordMapper.insert(userVoucherRecord);
        //将转账信息添加到消息盒子中
        //收账人
        MessageBoxModel messageBoxModel = new MessageBoxModel();
        messageBoxModel.setUserId(beneficiary.getId());
        messageBoxModel.setQuiltUserId(user.getId());
        messageBoxModel.setTypeName("到账通知");
        messageBoxModel.setVoucher(newTransferAmount.doubleValue());
        messageBoxModel.setNotes("好友" + user.getPhone() + "给您转账"+"(扣除"+handlingFees+"手续费)");
        messageBoxModel.setOrderSn(IdUtil.getSnowflakeNextIdStr());
        messageBoxModel.setCreateTime(CommonHelp.getNowTimestamp());
        messageBoxMapper.insert(messageBoxModel);
        //分账
        this.dividedIntoRecordService.dividingByRegionalAgent(user, beneficiary, BigDecimal.valueOf(handlingFees), IdUtil.fastSimpleUUID(), 1);
        user.setMobilePhoneNumberOppositeTransferAccount(beneficiary.getPhone());
        return user;
    }


    /**
     * merchanttomember凭证转移逻辑
     *
     * @param beneficiary    受益人
     * @param transferAmount 转账金额
     * @param user           用户
     */
    public void merchanttomemberVoucherTransferLogic(UserModel beneficiary, Double transferAmount, UserModel user)
    {

        //手续费
        double handlingFees = 0;
        //谁收券抽谁的
        BigDecimal newTransferAmount = BigDecimal.valueOf(transferAmount).subtract(BigDecimal.valueOf(handlingFees));

        beneficiary.setVoucher(beneficiary.getVoucher() + transferAmount - handlingFees);
        userMapper.updateById(beneficiary);

        UserModel businessUserEntity=this.userService.getById(user.getId());
        businessUserEntity.setVoucher(businessUserEntity.getVoucher() - transferAmount);
        userMapper.updateById(businessUserEntity);

        //生成转账记录
        TransferRecordsModel transferRecordsModel = new TransferRecordsModel();
        transferRecordsModel.setUserId(user.getId());
        //添加收款人
        transferRecordsModel.setCollectionId(beneficiary.getId());
        transferRecordsModel.setAmount(newTransferAmount.toString());
        transferRecordsModel.setHandlingFees(handlingFees);
        transferRecordsModel.setProportion(0D);
        transferRecordsModel.setCreateTime(CommonHelp.getNowTimestamp());
        transferRecordsMapper.insert(transferRecordsModel);

        //生成转账人益联券使用记录
        VoucherRecordModel quiltUserVoucherRecord = new VoucherRecordModel();
        quiltUserVoucherRecord.setName("好友转账");
        quiltUserVoucherRecord.setTypeName("好友转账");
        quiltUserVoucherRecord.setContent("向" + beneficiary.getPhone() + "转账");
        String amountVoucher = "-" + transferAmount + "券";
        quiltUserVoucherRecord.setVoucher(amountVoucher);
        quiltUserVoucherRecord.setUserId(user.getId());
        quiltUserVoucherRecord.setVoucherType(0);
        quiltUserVoucherRecord.setFees(BigDecimal.valueOf(handlingFees));
        quiltUserVoucherRecord.setVoucherAmount(-newTransferAmount.doubleValue());
        quiltUserVoucherRecord.setCreateTime(CommonHelp.getNowTimestamp());
        voucherRecordMapper.insert(quiltUserVoucherRecord);

        //消息盒子记录数据两条
        MessageBoxModel messageBoxModel0 = new MessageBoxModel();
        //转账人
        messageBoxModel0.setUserId(user.getId());
        messageBoxModel0.setQuiltUserId(user.getId());
        messageBoxModel0.setTypeName("转账通知");
        //需要显示原代金券
        messageBoxModel0.setVoucher(transferAmount.doubleValue());
        messageBoxModel0.setNotes("向" + beneficiary.getPhone() + "转账");
        messageBoxModel0.setCreateTime(CommonHelp.getNowTimestamp());
        messageBoxModel0.setOrderSn(IdUtil.getSnowflakeNextIdStr());
        messageBoxMapper.insert(messageBoxModel0);


        MessageBoxModel messageBoxModel = new MessageBoxModel();
        messageBoxModel.setUserId(beneficiary.getId());
        messageBoxModel.setQuiltUserId(user.getId());
        messageBoxModel.setTypeName("到账通知");
        messageBoxModel.setVoucher(newTransferAmount.doubleValue());
        messageBoxModel.setNotes("商家" + user.getPhone() + "给您转账");
        messageBoxModel.setOrderSn(IdUtil.getSnowflakeNextIdStr());
        messageBoxModel.setCreateTime(CommonHelp.getNowTimestamp());
        messageBoxMapper.insert(messageBoxModel);

        //生成被转账人益联券使用记录
        VoucherRecordModel userVoucherRecord = new VoucherRecordModel();
        userVoucherRecord.setName("好友转账");
        userVoucherRecord.setTypeName("收到好友转账");
        userVoucherRecord.setContent("收到" + user.getPhone() + "转账");
        String amountVoucherUser = "+" + (newTransferAmount.doubleValue()) + "券";
        userVoucherRecord.setVoucher(amountVoucherUser);
        userVoucherRecord.setUserId(beneficiary.getId());
        userVoucherRecord.setCreateTime(CommonHelp.getNowTimestamp());
        userVoucherRecord.setVoucherType(1);
        userVoucherRecord.setVoucherAmount(newTransferAmount.doubleValue());
        voucherRecordMapper.insert(userVoucherRecord);
    }



    /**
     * 手动分配邀请关系
     */
    @Override
    @RedisLockAnnotation(prefix = "manuallyAssignInvitationRelationships", key = "#orderSn")
    public void manuallyAssignInvitationRelationships(String orderSn,Integer userId)
    {

        InviteConfigModel inviteConfig = inviteConfigMapper.selectById(1);
        QueryWrapper<InviteRecordModel> inviteRecordModelQueryWrapper = new QueryWrapper<>();
        inviteRecordModelQueryWrapper.eq("quilt_invite_id", userId);
        InviteRecordModel recordModel = inviteRecordService.getOne(inviteRecordModelQueryWrapper);
        if (recordModel != null) {
            QueryWrapper<InviteRecordModel> inviteRecordModelQueryWrapper1 = new QueryWrapper<>();
            inviteRecordModelQueryWrapper1.eq("invite_id", recordModel.getInviteId())
                    .eq("status", 2)
                    .eq("is_act", 1);
            inviteRecordModelQueryWrapper1.orderByDesc("create_time");
            List<InviteRecordModel> recordModelList = inviteRecordService.list(inviteRecordModelQueryWrapper1);

            UserModel inviteUser = userMapper.selectById(recordModel.getInviteId());
            int count = recordModelList.size() + 1;
            if (count == (inviteConfig.getInviteCount())) {
                inviteUser.setVoucher(inviteUser.getVoucher() + inviteConfig.getInviteVoucher());
                userMapper.updateById(inviteUser);
                //新增券记录
                VoucherRecordModel voucherRecordModel1 = new VoucherRecordModel();
                voucherRecordModel1.setName("邀请好友获得益联券");
                voucherRecordModel1.setTypeName("邀请好友");
                String amountIntegral = "+" + inviteConfig.getInviteVoucher() + "券";
                voucherRecordModel1.setVoucher(amountIntegral);
                voucherRecordModel1.setUserId(inviteUser.getId());
                voucherRecordModel1.setCreateTime(CommonHelp.getNowTimestamp());
                voucherRecordModel1.setVoucherType(1);
                voucherRecordModel1.setVoucherAmount(Double.valueOf(inviteConfig.getInviteVoucher()));
                voucherRecordMapper.insert(voucherRecordModel1);
                //
                recordModel.setStatus(2);
                recordModel.setIsAct(0);
                inviteRecordService.updateById(recordModel);
                //消息盒子记录数据
                MessageBoxModel messageBoxModel = new MessageBoxModel();
                messageBoxModel.setUserId(inviteUser.getId());
                messageBoxModel.setQuiltUserId(inviteUser.getId());
                messageBoxModel.setTypeName("奖励通知");
                messageBoxModel.setVoucher(Double.valueOf(inviteConfig.getInviteVoucher()));
                messageBoxModel.setNotes("邀请好友满足额度");
                messageBoxModel.setCreateTime(CommonHelp.getNowTimestamp());
                messageBoxModel.setOrderSn(orderSn);
                messageBoxMapper.insert(messageBoxModel);
                //使曾经邀请的人邀请关系失效
                recordModelList.stream().forEach(s -> s.setIsAct(0));
                this.inviteRecordService.updateBatchById(recordModelList);
            }
        }
    }

    @Override
    @RedisLockAnnotation(prefix = "completeVip", key = "#orderSn")
    public void completeVip(String orderSn) throws Exception {//成为vip
        InviteConfigModel inviteConfig = inviteConfigMapper.selectById(1);
        //奖励的券量
        Double rewardCouponAmount=inviteConfig.getVipGive();
        QueryWrapper<PayModel> payModelQueryWrapper = new QueryWrapper<>();
        payModelQueryWrapper.eq("order_id", orderSn);
        PayModel payModel = payMapper.selectOne(payModelQueryWrapper);
        if (payModel != null) {
            UserModel user = userMapper.selectById(payModel.getUserId());
            if (user.getVip() != 1) {
                user.setVoucher(user.getVoucher()+rewardCouponAmount);
                user.setVipOrderSn(orderSn);
                payModel.setStatus(1);
                payMapper.updateById(payModel);
                //分配会员权限
                updateUserInfo(user);

                //消息盒子
                MessageBoxModel message = new MessageBoxModel();
                message.setUserId(user.getId());
                message.setTypeName("开通会员成功通知");
                message.setVoucher(rewardCouponAmount);
                message.setNotes("充值会员奖励益联券");
                message.setCreateTime(CommonHelp.getNowTimestamp());
                message.setOrderSn(orderSn);
                messageBoxMapper.insert(message);

                //新增券记录
                VoucherRecordModel voucherRecordModel = new VoucherRecordModel();
                voucherRecordModel.setName("会员赠送");
                voucherRecordModel.setTypeName("会员开通");
                String amountVoucher = "+" + rewardCouponAmount + "券";
                voucherRecordModel.setVoucher(amountVoucher);
                voucherRecordModel.setUserId(user.getId());
                voucherRecordModel.setCreateTime(CommonHelp.getNowTimestamp());
                voucherRecordModel.setVoucherType(1);
                voucherRecordModel.setVoucherAmount(rewardCouponAmount);
                voucherRecordMapper.insert(voucherRecordModel);
                
                 QueryWrapper<InviteRecordModel> inviteRecordModelQueryWrapper = new QueryWrapper<>();
                inviteRecordModelQueryWrapper.eq("quilt_invite_id", user.getId());
                InviteRecordModel recordModel = inviteRecordService.getOne(inviteRecordModelQueryWrapper);
                if (recordModel != null) {
                    QueryWrapper<InviteRecordModel> inviteRecordModelQueryWrapper1 = new QueryWrapper<>();
                    inviteRecordModelQueryWrapper1.eq("invite_id", recordModel.getInviteId())
                            .eq("status", 2)
                            .eq("is_act",1);
                    inviteRecordModelQueryWrapper1.orderByDesc("create_time");
                    List<InviteRecordModel> recordModelList = inviteRecordService.list(inviteRecordModelQueryWrapper1);


                    UserModel inviteUser = userMapper.selectById(recordModel.getInviteId());
                    int count=recordModelList.size()+1;
                    if (count==(inviteConfig.getInviteCount())) {
                        inviteUser.setVoucher(inviteUser.getVoucher() + inviteConfig.getInviteVoucher());
                        userMapper.updateById(inviteUser);
                        //新增券记录
                        VoucherRecordModel voucherRecordModel1 = new VoucherRecordModel();
                        voucherRecordModel1.setName("邀请好友获得益联券");
                        voucherRecordModel1.setTypeName("邀请好友");
                        String amountIntegral = "+" + inviteConfig.getInviteVoucher() + "券";
                        voucherRecordModel1.setVoucher(amountIntegral);
                        voucherRecordModel1.setUserId(inviteUser.getId());
                        voucherRecordModel1.setCreateTime(CommonHelp.getNowTimestamp());
                        voucherRecordModel1.setVoucherType(1);
                        voucherRecordModel1.setVoucherAmount(Double.valueOf(inviteConfig.getInviteVoucher()));
                        voucherRecordMapper.insert(voucherRecordModel1);
                        //
                        recordModel.setStatus(2);
                        recordModel.setIsAct(0);
                        inviteRecordService.updateById(recordModel);
                        //消息盒子记录数据
                        MessageBoxModel messageBoxModel = new MessageBoxModel();
                        messageBoxModel.setUserId(inviteUser.getId());
                        messageBoxModel.setQuiltUserId(inviteUser.getId());
                        messageBoxModel.setTypeName("奖励通知");
                        messageBoxModel.setVoucher(Double.valueOf(inviteConfig.getInviteVoucher()));
                        messageBoxModel.setNotes("邀请好友满足额度");
                        messageBoxModel.setCreateTime(CommonHelp.getNowTimestamp());
                        messageBoxModel.setOrderSn(orderSn);
                        messageBoxMapper.insert(messageBoxModel);
                        //使曾经邀请的人邀请关系失效
                        recordModelList.stream().forEach(s->s.setIsAct(0));
                        this.inviteRecordService.updateBatchById(recordModelList);
                    }
                    else {
                        recordModel.setStatus(2);
                        recordModel.setIsAct(1);
                        inviteRecordService.updateById(recordModel);
                    }
                }
            }
            log.info("【会员开通成功】处理后的数据data={}", user);
        }
    }

    @Override
    public void generateInvitationCode(UserModel user) {
            //生成邀请码
            String randomString = null;
            try {
                // 执行业务逻辑
                int nextNumber = Integer.parseInt(invationCodeMapper.selectById(1).getInvationCode()) + 1;//邀请码
                randomString = String.format("%08d", nextNumber);
                InvitationCodeModel invitationCodeModel = new InvitationCodeModel();
                invitationCodeModel.setInvationCode(randomString);
                invitationCodeModel.setId(1);
                invationCodeMapper.updateById(invitationCodeModel);//更新数据库当前邀请码

                //邀请二维码
                user.setInvitationCode(randomString);
                long l = System.currentTimeMillis();
                user.setVipTime(new Timestamp(l));
                String invitationCode = "type=1&" + randomString;
                String invitationCodeFileUrl = System.getProperty("user.dir") + File.separator + "file" + File.separator + invitationCode + ".jpg";
                WxQrCode.generateQrCode(invitationCodeFileUrl, "pages/index/index", WechatUtil.redisToken(), randomString);
                user.setInvitationCodeUrl(DEFAULT_PDF_SERVICE_URL + invitationCode + ".jpg");
                try{
                    aliyunOSSUtils.objectStorageUploadFile(DEFAULT_PDF_SERVICE_URL + invitationCode + ".jpg",FileUtil.getInputStream(invitationCodeFileUrl));
                }catch (Exception e)
                {

                }
                //转账二维码
                String transferAccountsCode = "type=2&" + randomString;
                String transferAccountsCodePath = System.getProperty("user.dir") + File.separator + "file" + File.separator + transferAccountsCode + ".png";
                QrCodeUtil.generate(transferAccountsCode, 300, 300, FileUtil.file(transferAccountsCodePath));
                user.setTransferAccountsCodeUrl(DEFAULT_PDF_SERVICE_URL + transferAccountsCode + ".png");
                try{
                    aliyunOSSUtils.objectStorageUploadFile(DEFAULT_PDF_SERVICE_URL + transferAccountsCode + ".png",FileUtil.getInputStream(transferAccountsCodePath));
                }catch (Exception e)
                {

                }
                this.userService.updateById(user);
            } catch (Exception e) {
                e.printStackTrace();
            }

    }


    /**
     * 给用户加会员权限
     *
     * @param user
     * @throws Exception
     */
    public void updateUserInfo(UserModel user) throws Exception {
        //发送短信  就差配置阿里云短信code了
//        this.smsUtils.sendRechargeNotification(user.getPhone());
        if (user.getInvitationCode() != null) {
            user.setVip(1);
            user.setVipTime(new Timestamp(System.currentTimeMillis()));
            userMapper.updateById(user);
            return;
        }
        user.setVip(1);
        //生成邀请码
        String randomString = null;
        try {
            // 执行业务逻辑
            int nextNumber = Integer.parseInt(invationCodeMapper.selectById(1).getInvationCode()) + 1;//邀请码
            randomString = String.format("%08d", nextNumber);
            InvitationCodeModel invitationCodeModel = new InvitationCodeModel();
            invitationCodeModel.setInvationCode(randomString);
            invitationCodeModel.setId(1);
            invationCodeMapper.updateById(invitationCodeModel);//更新数据库当前邀请码
        } catch (Exception e) {
            e.printStackTrace();
        }
        //邀请二维码
        user.setInvitationCode(randomString);
        long l = System.currentTimeMillis();
        user.setVipTime(new Timestamp(l));
        String invitationCode = "type=1&" + randomString;
        String invitationCodeFileUrl = System.getProperty("user.dir") + File.separator + "file" + File.separator + invitationCode + ".jpg";
        WxQrCode.generateQrCode(invitationCodeFileUrl, "pages/index/index", WechatUtil.redisToken(), randomString);
        user.setInvitationCodeUrl(DEFAULT_PDF_SERVICE_URL + invitationCode + ".jpg");
        aliyunOSSUtils.objectStorageUploadFile(DEFAULT_PDF_SERVICE_URL + invitationCode + ".jpg",FileUtil.getInputStream(invitationCodeFileUrl));

        //转账二维码
        String transferAccountsCode = "type=2&" + randomString;
        String transferAccountsCodePath = System.getProperty("user.dir") + File.separator + "file" + File.separator + transferAccountsCode + ".png";
        QrCodeUtil.generate(transferAccountsCode, 300, 300, FileUtil.file(transferAccountsCodePath));
        user.setTransferAccountsCodeUrl(DEFAULT_PDF_SERVICE_URL + transferAccountsCode + ".png");
        aliyunOSSUtils.objectStorageUploadFile(DEFAULT_PDF_SERVICE_URL + transferAccountsCode + ".png",FileUtil.getInputStream(transferAccountsCodePath));

        //为会员分配客服
        QueryWrapper<CustomerServiceModel> customerServiceModelQueryWrapper = new QueryWrapper<>();
        customerServiceModelQueryWrapper.eq("status", 2);
        customerServiceModelQueryWrapper.eq("is_del", 2);
        List<CustomerServiceModel> list = customerServiceService.list(customerServiceModelQueryWrapper);
        CustomerServiceModel customerServiceModel = new CustomerServiceModel();
        if (list != null && !list.isEmpty()) {
            Integer count = 10000;
            for (CustomerServiceModel model : list) {
                List<Integer> intList = convertStringToIntList(model.getVipIds(), ",");
                intList.add(user.getId());
                String b = convertIntListToString(intList, ",");
                customerServiceMapper.updateById(model);
                if (model.getNowNum() < count) {
                    customerServiceModel = model;
                    customerServiceModel.setVipIds(b);
                }
            }
        }
        user.setCustomerServiceId(customerServiceModel.getId());
        userMapper.updateById(user);
        try{
            FileUtil.del(FileUtil.file(invitationCodeFileUrl));
            FileUtil.del(FileUtil.file(transferAccountsCodePath));
        }catch (Exception e)
        {
            e.printStackTrace();
        }
    }



    /**
     * 再生
     *
     * @param user 用户
     * @throws Exception 例外
     */
    @Override
    public void regenerate(UserModel user) throws Exception {

        String randomString = user.getInvitationCode();
        //邀请二维码
        String invitationCode = "type=1&" + randomString;
        String invitationCodeFileUrl = System.getProperty("user.dir") + File.separator + "file" + File.separator + invitationCode + ".jpg";
        WxQrCode.generateQrCode(invitationCodeFileUrl, "pages/index/index", WechatUtil.redisToken(), randomString);
        user.setInvitationCodeUrl(DEFAULT_PDF_SERVICE_URL + invitationCode + ".jpg");
        aliyunOSSUtils.objectStorageUploadFile(DEFAULT_PDF_SERVICE_URL + invitationCode + ".jpg",FileUtil.getInputStream(invitationCodeFileUrl));

        //转账二维码
        String transferAccountsCode = "type=2&" + randomString;
        String transferAccountsCodePath = System.getProperty("user.dir") + File.separator + "file" + File.separator + transferAccountsCode + ".png";
        QrCodeUtil.generate(transferAccountsCode, 300, 300, FileUtil.file(transferAccountsCodePath));
        user.setTransferAccountsCodeUrl(DEFAULT_PDF_SERVICE_URL + transferAccountsCode + ".png");
        aliyunOSSUtils.objectStorageUploadFile(DEFAULT_PDF_SERVICE_URL + transferAccountsCode + ".png",FileUtil.getInputStream(transferAccountsCodePath));

        userMapper.updateById(user);
        try{
            FileUtil.del(FileUtil.file(invitationCodeFileUrl));
            FileUtil.del(FileUtil.file(transferAccountsCodePath));
        }catch (Exception e)
        {
            e.printStackTrace();
        }
    }


    public static List<Integer> convertStringToIntList(String str, String delimiter) {
        if (StrUtil.isBlank(str)) {
            return new ArrayList<>();
        }
        // 使用给定的分隔符分割字符串
        String[] items = str.split(delimiter);

        // 创建一个列表来保存整数
        List<Integer> intList = new ArrayList<>();

        // 将每个字符串转换为整数并添加到列表中
        for (String item : items) {
            intList.add(Integer.parseInt(item.trim())); // trim()用于去除字符串两端的空白字符
        }

        return intList;
    }


    @Override
    @RedisLockAnnotation(prefix = "upVip", key = "#userId")
    public Object upVip(String orderSn, String openId, String ip,UserModel userModel,Integer userId) {
        List<InviteConfigModel> inviteConfigModelList = inviteConfigService.list();
        WxPayUnifiedOrderRequest requestBody = new WxPayUnifiedOrderRequest();
        requestBody.setAttach("vip会员服务");
        requestBody.setBody("vip会员服务");
        requestBody.setOutTradeNo(orderSn);
        requestBody.setTotalFee(PriceUtils.changeY2F(inviteConfigModelList.get(0).getVipPrice()));
        requestBody.setSpbillCreateIp(ip);
        requestBody.setNotifyUrl(payNotify);
        requestBody.setOpenid(openId);
        requestBody.setTradeType(WxPayConstants.TradeType.JSAPI);
        PayModel payModel = new PayModel();


        if (userModel != null) {
            payModel.setName(userModel.getName());
            payModel.setPhone(userModel.getPhone());
        }
        payModel.setUserId(userModel.getId());
        payModel.setOrderId(orderSn);
        payModel.setOpenid(openId);
        payModel.setPrice(inviteConfigModelList.get(0).getVipPrice());
        payModel.setCreateTime(CommonHelp.getNowTimestamp());
        payModel.setStatus(2);
        try {
            Object response = this.wxService.switchoverTo(mchId).createOrder(requestBody);
            log.info(JSONUtil.toJsonStr(response));
            JSONObject object = JSONUtil.parseObj(response);
            object.set("package", object.getStr("packageValue"));
            object.set("prePayParams", mchId);
            object.set("orderSn", orderSn);
            payMapper.insert(payModel);
            return object;
        } catch (WxPayException e) {
            log.info("请求失败,{}", e.getReturnMsg());
            payMapper.insert(payModel);
            throw new BaseException(201, e.getReturnMsg());
        }
    }


    @Override
    public UserModel getUserByInviteCode(String invitationCode) {
        QueryWrapper<UserModel> userModelQueryWrapper = new QueryWrapper<>();
        userModelQueryWrapper.eq("invitation_code", invitationCode);
        return userMapper.selectOne(userModelQueryWrapper);
    }

    @Override
    public UserModel getUserByInviteCodeOrPhone(String invitationCode) {
        QueryWrapper<UserModel> userModelQueryWrapper = new QueryWrapper<>();
        userModelQueryWrapper.eq("invitation_code", invitationCode).or().eq("phone", invitationCode);
        return userMapper.selectOne(userModelQueryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void userGrant(Integer id, Double voucherAmount, Double integral) {
        UserModel userModel = userMapper.selectById(id);
        if (userModel != null) {
            userModel.setVoucher(userModel.getVoucher() + voucherAmount);
            userModel.setIntegral(userModel.getIntegral() + integral);
            userMapper.updateById(userModel);
            DistributionRecord distributionRecord = new DistributionRecord();
            VoucherRecordModel voucherRecordModel = new VoucherRecordModel();
            if (voucherAmount > 0) {
                //增加益联券记录
                voucherRecordModel.setName("益联券发放");
                voucherRecordModel.setTypeName("益联券发放");
                String amountVoucher = "+" + voucherAmount + "券";
                voucherRecordModel.setVoucher(amountVoucher);
                voucherRecordModel.setUserId(userModel.getId());
                voucherRecordModel.setCreateTime(CommonHelp.getNowTimestamp());
                voucherRecordModel.setVoucherType(1);
                voucherRecordModel.setVoucherAmount(voucherAmount);
                voucherRecordMapper.insert(voucherRecordModel);
                //消息盒子记录数据
                MessageBoxModel messageBoxModel = new MessageBoxModel();
                messageBoxModel.setUserId(userModel.getId());
                messageBoxModel.setQuiltUserId(userModel.getId());
                messageBoxModel.setTypeName("到账通知");
                messageBoxModel.setVoucher(voucherAmount);
                messageBoxModel.setNotes("益联券发放");
                messageBoxModel.setCreateTime(CommonHelp.getNowTimestamp());
                messageBoxMapper.insert(messageBoxModel);
                distributionRecord.setAmount(BigDecimal.valueOf(voucherAmount));
                distributionRecord.setAmountDistributionType(1);
            } else if(voucherAmount<0) {
                //增加益联券记录
                voucherRecordModel.setName("益联券扣减");
                voucherRecordModel.setTypeName("益联券扣减");
                String amountVoucher = voucherAmount + "券";
                voucherRecordModel.setVoucher(amountVoucher);
                voucherRecordModel.setUserId(userModel.getId());
                voucherRecordModel.setCreateTime(CommonHelp.getNowTimestamp());
                voucherRecordModel.setVoucherType(0);
                voucherRecordModel.setVoucherAmount(voucherAmount);
                voucherRecordMapper.insert(voucherRecordModel);
                //消息盒子记录数据
                MessageBoxModel messageBoxModel = new MessageBoxModel();
                messageBoxModel.setUserId(userModel.getId());
                messageBoxModel.setQuiltUserId(userModel.getId());
                messageBoxModel.setTypeName("扣减通知");
                messageBoxModel.setVoucher(voucherAmount);
                messageBoxModel.setNotes("益联券扣减");
                messageBoxModel.setCreateTime(CommonHelp.getNowTimestamp());
                messageBoxMapper.insert(messageBoxModel);
                distributionRecord.setAmount(BigDecimal.valueOf(voucherAmount));
                distributionRecord.setAmountDistributionType(2);
            }
            IntegralRecordModel integralRecordModel = new IntegralRecordModel();
            if (integral > 0) {
                //增加积分记录
                integralRecordModel.setName("积分发放");
                integralRecordModel.setTypeName("发放");
                String amountIntegral = "+" + integral + "分";
                integralRecordModel.setIntegral(amountIntegral);
                integralRecordModel.setUserId(userModel.getId());
                integralRecordModel.setCreateTime(CommonHelp.getNowTimestamp());
                integralRecordModel.setVoucherType(1);
                integralRecordModel.setVoucherAmount(integral);
                integralRecordService.save(integralRecordModel);
                distributionRecord.setIntegral(BigDecimal.valueOf(integral));
                distributionRecord.setIntegralDistributionType(1);
            } else if(integral<0) {
                //增加积分记录
                if (integral!=0.0){
                    integralRecordModel.setName("积分扣减");
                    integralRecordModel.setTypeName("扣减");
                    String amountIntegral = integral + "分";
                    integralRecordModel.setIntegral(amountIntegral);
                    integralRecordModel.setUserId(userModel.getId());
                    integralRecordModel.setCreateTime(CommonHelp.getNowTimestamp());
                    integralRecordModel.setVoucherType(0);
                    integralRecordModel.setVoucherAmount(integral);
                    integralRecordService.save(integralRecordModel);
                }
                distributionRecord.setIntegral(BigDecimal.valueOf(integral));
                distributionRecord.setIntegralDistributionType(2);
            }
            //增加发放记录
            distributionRecord.setBusinessId(id);
            distributionRecord.setUserId(userModel.getId());
            distributionRecord.setType(2);
            distributionRecord.setDistributionTime(CommonHelp.getNowTimestamp());
            distributionRecord.setCreateTime(CommonHelp.getNowTimestamp());
            distributionRecordsMapper.insert(distributionRecord);
        }
    }

    @Override
    public void setPaymentPassword(String paymentPassword, UserModel user) {
        String salt = RandomUtil.randomString(8);
        String newWord = md5Hex(paymentPassword + salt);
        user.setPaymentPassword(newWord);
        user.setSalt(salt);
        userMapper.updateById(user);
    }

    @Override
    public UserModel getUserByPhone(String phone) {
        QueryWrapper<UserModel> userModelQueryWrapper = new QueryWrapper<>();
        userModelQueryWrapper.eq("phone", phone);
        return userMapper.selectOne(userModelQueryWrapper);
    }

    @Override
    public List<JSONObject> userConsumptionVoucherStatistics(AdminUserModel userModel) {
        return this.baseMapper.userConsumptionVoucherStatistics(userModel);
    }

    @Override
    public UserModel getUserInfoByOpenid(String openId, String cityId, String areaId) {
        QueryWrapper<UserModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("open_id", openId);
        queryWrapper.eq(StrUtil.isNotBlank(cityId), "city_id", cityId);
        queryWrapper.eq(StrUtil.isNotBlank(areaId), "area_id", areaId);
        return userMapper.selectOne(queryWrapper);
    }

    @Autowired
    private WatermarkUtil watermarkUtil;
    @Override
    public UserModel generateBeautifiedTwodimensionalCode(UserModel userModel) {

        userModel.setBeautifyAccountsCodeUrl(watermarkUtil.generateCollectionCode(userModel.getFaceUrl(),userModel.getName(),userModel.getTransferAccountsCodeUrl()));
        userModel.setBeautifyInvitationCodeUrl(watermarkUtil.generateInvitationCode(userModel.getFaceUrl(),userModel.getName(),userModel.getInvitationCodeUrl()));

        this.userService.updateById(userModel);


        return userModel;
    }

    /**
     * 查询用户是否是刚刚成为会员
     * @param user
     * @return
     */
    @Override
    public Result ifBecomeVipJustNow(UserModel user) {
        // 假设 user.getVipTime() 返回的是 Timestamp 类型
        Timestamp vipTime = user.getVipTime();
        // 获取当前时间，并设置为中国时区
        ZonedDateTime nowInChina = ZonedDateTime.now(ZoneId.of("Asia/Shanghai"));
        // 将 Timestamp 转换为 ZonedDateTime，设置为中国时区
        ZonedDateTime vipZonedDateTime = vipTime.toInstant().atZone(ZoneId.of("Asia/Shanghai"));
        // 计算两个时间点之间的持续时间
        Duration duration = Duration.between(vipZonedDateTime, nowInChina);
        // 判断是否在五分钟之内
        if (duration.toMinutes() < 1 && !duration.isNegative()) {
//            System.out.println("VIP 时间在一分钟之内");
            return Result.success(true);
        } else {
//            System.out.println("VIP 时间不在一分钟之内");
            return Result.success(false);
        }
    }

    public static void main(String[] args) {
        File fileTarget=FileUtil.file(System.getProperty("user.dir")+File.separator+"/file/style/"+IdUtil.fastSimpleUUID()+".png");




        FileUtil.getInputStream(FileUtil.file(System.getProperty("user.dir")+File.separator+"/file/templeate/yaoqing.png"));
        FileUtil.getInputStream(FileUtil.file(System.getProperty("user.dir")+File.separator+"/file/type=1&00000077.jpg"));

    }
}
